package com.mercury.pattern._01_singleton.hungry.type01;

/**
 * 饿汉式1：静态变量方式
 */
public class SingletonTest01 {

    //测试
    public static void main(String[] args) {
        Singleton instance = Singleton.getInstance();
        Singleton instance2 = Singleton.getInstance();
        System.out.println(instance == instance2);
        System.out.println(instance.hashCode());
        System.out.println(instance2.hashCode());
    }

}

class Singleton{
    /**
     * 1、私有构造方法
     * 2、私有且不能修改的对象，在全局变量中就会创建
     * 3、通过静态方法返回该对象
     */

    private static final Singleton instance = new Singleton();

    private Singleton(){

    }

    public static Singleton getInstance(){
        return instance;
    }
}
